package com.gorkr;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gorkr
 * @date 2022/01/12 23:40
 **/

class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}
public class L6 {

        List<Integer> tmp = new ArrayList<Integer>();
        public int[] reversePrint(ListNode head) {
            recurr(head);
            int[] res = new int[tmp.size()];
            for(int i = 0; i < res.length; i++) {
                res[i] = tmp.get(i);
            }
            return res;
        }

        // 递归返回
        public void recurr(ListNode head){
            if(head.next!=null){
                recurr(head.next);
            }
            tmp.add(head.val);
        }

        @Test
        public void test(){
            ListNode a = new ListNode(1);
            ListNode b = new ListNode(2);
            a.next = b;

            System.out.println(reversePrint(a));

        }
}
    